﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using EasyMail;

namespace Spammer
{
    /// <summary>
    /// A simple program to repeatedly send a message in order to test the EasyMail namespace
    /// </summary>
    class Spammer
    {
        static String toAddress;
        static String fromAddress;
        static String password;
        static String body;
        static int messageCount;
        static bool couldParseInputForMessageCount;

        /// <summary>
        /// Sends a message
        /// </summary>
        static void Main(string[] args)
        {
            Console.WriteLine("######################");
            Console.WriteLine("#     WELCOME TO     #");
            Console.WriteLine("#   THE STUPENDOUS   #");
            Console.WriteLine("#  EASYMAIL SPAMMER  #");
            Console.WriteLine("######################");
            Console.WriteLine();
            Console.WriteLine("Currently set to Outlook.com");
            Console.WriteLine();

            Console.WriteLine("Enter your email address: ");
            fromAddress = Console.ReadLine();
            Console.WriteLine();

            Console.WriteLine("Enter your email password: ");
            password = Console.ReadLine();
            Console.WriteLine();

            Console.WriteLine("Enter the email address of your recipient: ");
            toAddress = Console.ReadLine();
            Console.WriteLine();

            Console.WriteLine("Enter the body of your email: ");
            body = Console.ReadLine();
            Console.WriteLine();

            Console.WriteLine("How many messages would you like to send? Input answer as in integer less than or equal to 25,000.");
            couldParseInputForMessageCount = int.TryParse(Console.ReadLine(), out messageCount);
            if (!couldParseInputForMessageCount)
            {
                Console.WriteLine("Please use an integer.");
                Console.WriteLine("Press enter to quit.");
                Console.ReadLine();
                return;
            }
            if (messageCount > 25000 || messageCount <= 0)
            {
                Console.WriteLine("Please stay within 25,000 and 0.");
                Console.WriteLine("Press enter to quit.");
                Console.ReadLine();
                return;
            }
            EasyMailMessage message = new EasyMailMessage(toAddress, fromAddress, "Spam test", body);
            for (int i = 1; i <= messageCount; i++)
            {
                OutlookComSender.Send(message, password);
                Console.WriteLine("Sent message " + i);
            }

            // Prevent automatic dimissal by Windows.
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Press enter to quit.");
            Console.ReadLine();
        }

        /*
        public static string ReadPassword() {
             Stack passbits = new Stack();
             //keep reading
             for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true)) {
                if (cki.Key == ConsoleKey.Backspace)
                {
                    //rollback the cursor and write a space so it looks backspaced to the user
                    Console.SetCursorPosition(Console.CursorLeft – 1, Console.CursorTop);
                    Console.Write(" ");
                    Console.SetCursorPosition(Console.CursorLeft – 1, Console.CursorTop);
                    passbits.Pop();
                }
                else
                {
                    Console.Write("*");
                    passbits.Push(cki.KeyChar.ToString());
                }
             }
             string[] pass = passbits.ToArray();
             Array.Reverse(pass);
             return string.Join(string.Empty, pass);
         }
        */
    }
}
